package com.jingdianjichi.subject.domain.handler.Subject;

import com.jingdianjichi.subject.common.enums.IsDeleteFlagEnum;
import com.jingdianjichi.subject.common.enums.SubjectTypeEnums;
import com.jingdianjichi.subject.domain.convert.BriefSubjectConverter;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 简答策略类
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectBriefService subjectBriefService;
    @Override
    public void add(SubjectInfoBO subjectInfobo) {
            SubjectBrief subjectBrief= BriefSubjectConverter.INSTANCE.convertBoToInfo(subjectInfobo);
            subjectBrief.setSubjectId(subjectInfobo.getId().intValue());
            subjectBrief.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());
            subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectTypeEnums getSubjectType() {

        return  SubjectTypeEnums.BIREF;
    }

    @Override
    public SubjectOptionBo query(Long id) {
        SubjectBrief subjectBrief=new SubjectBrief();
        subjectBrief.setSubjectId(id.intValue());
        SubjectBrief result=subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBo subjectOptionBo=new SubjectOptionBo();
        subjectOptionBo.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBo;
    }
}
